package com.reebake.ideal.message.websocket.config;

import com.reebake.ideal.message.websocket.core.RedisWebsocketMessageListener;
import com.reebake.ideal.message.websocket.core.RedisWebsocketMessagePublisher;
import com.reebake.ideal.message.websocket.core.WebsocketConstants;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

@Configuration
@ConditionalOnClass(RedisTemplate.class)
public class WebsocketRedisConfig {

	@Bean
    RedisWebsocketMessageListener redisWebsocketMessageListener(RedisMessageListenerContainer listenerContainer) {
		return new RedisWebsocketMessageListener(listenerContainer);
	}

    @Bean
    RedisWebsocketMessagePublisher websocketMessagePublisher(RedisTemplate<String, Object> redisTemplate) {
    	return new RedisWebsocketMessagePublisher(redisTemplate, WebsocketConstants.QUEUE_NAME_WEBSOCKET_CHANNEL_TOPIC);
    }
}
